//
//  WorkerBaseView.m
//  Btpin
//
//  Created by Vic on 2019/3/26.
//  Copyright © 2019 Vic. All rights reserved.
//

#import "WorkerBaseView.h"

@interface WorkerBaseView ()
{
    UIImageView *headerImgView;
    UILabel *nameLbl;
    UILabel *baseInfoLbl;
    UILabel *workInfoLbl;
    UILabel *intentionLbl;
    UILabel *timeLbl;
    
    UIImageView *tagImgView;
}
@end

@implementation WorkerBaseView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self initUI];
    }
    return self;
}
- (void)initUI {
    self.backgroundColor = COLOR_OF_WHITE;
    headerImgView = [UIToolsControl initImageViewWithFrame:CGRectMake(LeftSpace, 20*Scale, 50*Scale, 50*Scale) imageName:@"header_bg"];
    headerImgView.contentMode = UIViewContentModeScaleAspectFill;
    headerImgView.layer.cornerRadius = 25*Scale;
    headerImgView.layer.masksToBounds = YES;
    [self addSubview:headerImgView];
    
    tagImgView = [UIToolsControl initImageViewWithFrame:CGRectMake(EndX(headerImgView)-15*Scale, EndY(headerImgView)-10*Scale, 12*Scale, 12*Scale) imageName:@"worker_tag"];
    [self addSubview:tagImgView];
    
    nameLbl = [UIToolsControl initLabelWithFrame:CGRectMake(EndX(headerImgView)+10*Scale, 15*Scale, 100, 30*Scale) text:nil textColor:THEMECOLOR_OF_TEXT_333333 font:Font_18];
    nameLbl.font = FontBold(Font_18);
    [self addSubview:nameLbl];
    
    baseInfoLbl = [UIToolsControl initLabelWithFrame:CGRectMake(EndX(nameLbl), 15*Scale, 200, 25*Scale) text:nil textColor:THEMECOLOR_OF_TEXT_666666 font:Font_14];
    [self addSubview:baseInfoLbl];
    
    workInfoLbl = [UIToolsControl initLabelWithFrame:CGRectMake(StartX(nameLbl), EndY(nameLbl), WIDTH-100*Scale, 25*Scale) text:nil textColor:THEMECOLOR_OF_TEXT_666666 font:Font_14];
    [self addSubview:workInfoLbl];
    
    intentionLbl = [UIToolsControl initLabelWithFrame:CGRectMake(StartX(nameLbl), EndY(workInfoLbl), WIDTH-100*Scale, 25*Scale) text:nil textColor:THEMECOLOR_OF_TEXT_666666 font:Font_13];
    [self addSubview:intentionLbl];
    
    timeLbl = [UIToolsControl initLabelWithFrame:CGRectMake(0, 0, WIDTH-15*Scale, 55*Scale) text:nil textColor:THEMECOLOR_OF_TEXT_9a9a9a font:Font_12];
    timeLbl.backgroundColor = COLOR_OF_CLEAR;
    timeLbl.textAlignment = NSTextAlignmentRight;
    [self addSubview:timeLbl];
}
- (void)reloadData {
    NSString *name = @"王小菲";
    CGFloat nameWidth = [UIToolsControl textWidth:name size:CGSizeMake(MAXFLOAT, 30*Scale) font:Font_18]+10*Scale;
    nameLbl.frame = CGRectMake(EndX(headerImgView)+10*Scale, 15*Scale, nameWidth, 30*Scale);
    nameLbl.text = name;
    
    baseInfoLbl.frame = CGRectMake(EndX(nameLbl), 17*Scale, 200, 25*Scale);
    baseInfoLbl.text = @"女 | 27岁 | 本科";
    
    NSString *workInfo1 = @"工作经验：5年 期望薪资：20-30k";
    NSString *workInfo2 = @"工作经验：5年 期望薪资：";
    NSMutableAttributedString *workAtt = [[NSMutableAttributedString alloc] initWithString:workInfo1];
    
    [workAtt addAttribute:NSForegroundColorAttributeName value:THEMECOLOR_OF_RED range:NSMakeRange(0, workInfo1.length)];
    [workAtt addAttribute:NSForegroundColorAttributeName value:THEMECOLOR_OF_TEXT_666666 range:NSMakeRange(0, workInfo2.length)];
    workInfoLbl.attributedText = workAtt;
    
    NSString *intention1 = @"意向职位：互联网运营总监";
    NSString *intention2 = @"意向职位：";
    NSMutableAttributedString *intentionAtt = [[NSMutableAttributedString alloc] initWithString:intention1];
    [intentionAtt addAttributes:@{NSFontAttributeName:Font(Font_15), NSForegroundColorAttributeName:THEMECOLOR_OF_TEXT_333333} range:NSMakeRange(0, intention1.length)];
    [intentionAtt addAttributes:@{NSFontAttributeName:Font(Font_13), NSForegroundColorAttributeName:THEMECOLOR_OF_TEXT_666666} range:NSMakeRange(0, intention2.length)];
    intentionLbl.attributedText = intentionAtt;
    
    timeLbl.text = @"02月-11日";
}
- (void)reloadDataModel:(WorkerModel *)model {
    if (model.avatar && model.avatar.length) {
        [headerImgView sd_setImageWithURL:[NSURL URLWithString:model.avatar] placeholderImage:[UIImage imageNamed:@"header_bg"]];
    } else {
        headerImgView.image = [UIImage imageNamed:@"header_bg"];
    }
    
    NSInteger avatar = [model.auth_medal integerValue];
    if (avatar) {
        tagImgView.hidden = NO;
    } else {
        tagImgView.hidden = YES;
    }
    
    CGFloat nameWidth = [UIToolsControl textWidth:model.name size:CGSizeMake(MAXFLOAT, 30*Scale) font:Font_18]+10*Scale;
    nameLbl.frame = CGRectMake(EndX(headerImgView)+10*Scale, 15*Scale, nameWidth, 30*Scale);
    nameLbl.text = model.name?model.name:@"";
    
    baseInfoLbl.frame = CGRectMake(EndX(nameLbl), 17*Scale, 200, 25*Scale);
    baseInfoLbl.text = [NSString stringWithFormat:@"%@ | %@ | %@ | %@", model.sex_cn?model.sex_cn:@"", model.age?model.age:@"", model.education_cn?model.education_cn:@"", model.experience_cn?model.experience_cn:@""];
    
    NSString *workInfo1 = [NSString stringWithFormat:@"期望薪资：%@",  model.wage_cn?model.wage_cn:@""];
    NSString *workInfo2 = @"期望薪资：";
    NSMutableAttributedString *workAtt = [[NSMutableAttributedString alloc] initWithString:workInfo1];
    [workAtt addAttribute:NSForegroundColorAttributeName value:THEMECOLOR_OF_RED range:NSMakeRange(0, workInfo1.length)];
    [workAtt addAttribute:NSForegroundColorAttributeName value:THEMECOLOR_OF_TEXT_666666 range:NSMakeRange(0, workInfo2.length)];
    workInfoLbl.attributedText = workAtt;
    
    if (model.job_title && model.job_title.length) {
        NSString *ssstr = model.job_title;
        
        NSString *intention1 = [NSString stringWithFormat:@"应聘职位：%@", ssstr];
        NSString *intention2 = @"应聘职位：";
        NSMutableAttributedString *intentionAtt = [[NSMutableAttributedString alloc] initWithString:intention1];
        [intentionAtt addAttributes:@{NSFontAttributeName:Font(Font_15), NSForegroundColorAttributeName:THEMECOLOR_OF_TEXT_333333} range:NSMakeRange(0, intention1.length)];
        [intentionAtt addAttributes:@{NSFontAttributeName:Font(Font_13), NSForegroundColorAttributeName:THEMECOLOR_OF_TEXT_666666} range:NSMakeRange(0, intention2.length)];
        intentionLbl.attributedText = intentionAtt;
    }else if (model.intention_jobs && model.intention_jobs.length) {
        NSString *ssstr = model.intention_jobs;
        
        NSString *intention1 = [NSString stringWithFormat:@"意向职位：%@", ssstr];
        NSString *intention2 = @"意向职位：";
        NSMutableAttributedString *intentionAtt = [[NSMutableAttributedString alloc] initWithString:intention1];
        [intentionAtt addAttributes:@{NSFontAttributeName:Font(Font_15), NSForegroundColorAttributeName:THEMECOLOR_OF_TEXT_333333} range:NSMakeRange(0, intention1.length)];
        [intentionAtt addAttributes:@{NSFontAttributeName:Font(Font_13), NSForegroundColorAttributeName:THEMECOLOR_OF_TEXT_666666} range:NSMakeRange(0, intention2.length)];
        intentionLbl.attributedText = intentionAtt;
    } else {
        if (model.intention_jobsArray && model.intention_jobsArray.count) {
            NSString *ssstr = @"";
            for (NSString *tempStr in model.intention_jobsArray) {
                ssstr = [NSString stringWithFormat:@"%@ %@", tempStr,  ssstr];
            }
            
            NSString *intention1 = [NSString stringWithFormat:@"意向职位：%@", ssstr];
            NSString *intention2 = @"意向职位：";
            NSMutableAttributedString *intentionAtt = [[NSMutableAttributedString alloc] initWithString:intention1];
            [intentionAtt addAttributes:@{NSFontAttributeName:Font(Font_15), NSForegroundColorAttributeName:THEMECOLOR_OF_TEXT_333333} range:NSMakeRange(0, intention1.length)];
            [intentionAtt addAttributes:@{NSFontAttributeName:Font(Font_13), NSForegroundColorAttributeName:THEMECOLOR_OF_TEXT_666666} range:NSMakeRange(0, intention2.length)];
            intentionLbl.attributedText = intentionAtt;
        } else {
            intentionLbl.text = @"意向职位：";
        }
    }
    
    switch (model.type) {
        case WorkerCellTypeOfNoTime: {
            timeLbl.text = @"";
        } break;
        case WorkerCellTypeOfOnlyTime: {
//            timeLbl.text = model.update_timeMMDD;
            timeLbl.text = model.showTime;
        } break;
        case WorkerCellTypeOfCollect: {
//            if (model.collectType == CollectTypeOfCompany) {
//                timeLbl.text = [NSString stringWithFormat:@"%@收藏", model.favorite_timeMMDD];
//            } else {
//                timeLbl.text = [NSString stringWithFormat:@"%@收藏", model.update_timeMMDD];
//            }
            timeLbl.text = [NSString stringWithFormat:@"%@收藏", model.showTime];
        } break;
        case WorkerCellTypeOfLook: {
//            timeLbl.text = [NSString stringWithFormat:@"%@查看了您", model.update_timeMMDD];
            timeLbl.text = [NSString stringWithFormat:@"%@", model.showTime];
        } break;
        default:
            break;
    }
}

@end
